package com.gitee.feizns.webtemplate.commons.data.page;

import com.gitee.feizns.webtemplate.commons.data.order.OrderBy;
import com.gitee.feizns.webtemplate.commons.data.order.OrderColumn;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.session.RowBounds;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author feizns
 * @since 2019/5/12 0012
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class OrderRowBounds extends RowBounds implements OrderBy, IPage {

    /**
     * 总数
     */
    private long total;

    /**
     * 起始位置
     */
    private int start;

    /**
     * 需要数量
     */
    private int size;

    /**
     * 优化 Count Sql 设置 false 执行 select count(1) from (listSql)
     */
    private boolean optimizeCountSql = true;

    /**
     * 查询总记录数（默认 true）
     */
    private boolean searchCount = true;

    public OrderRowBounds(int offset, int limit) {
        super(offset, limit);
    }

    public OrderRowBounds(int offset, int limit, OrderColumn... orderColumns) {
        super(offset, limit);
        this.orderColumns = Arrays.asList(orderColumns);
    }

    /**
     * 排序字段.
     */
    private List<OrderColumn> orderColumns;

    @Override
    public List<OrderColumn> orderBy() {
        return orderColumns == null ? Collections.emptyList() : orderColumns;
    }

    @Override
    public Integer getBeginPos() {
        return getStart();
    }

    @Override
    public Integer getCurtPage() {
        return null;
    }

    @Override
    public Integer getPageSize() {
        return getSize();
    }

    @Override
    public Long getPageCount() {
        return null;
    }

}
